const CryptoJS = require('crypto-js')

/**
 * 加密
 * @param {String} content 加密文本
 * @param {String} keyStr 加密key
 */
function encrypt(content, keyStr = 'etoF55gaHfgrER6e') {
	var key = CryptoJS.enc.Utf8.parse(keyStr);
	var text = CryptoJS.enc.Utf8.parse(content);
	var encrypted = CryptoJS.AES.encrypt(text, key, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}
/*

/**
 * 解密
 * @param {String} content 解密文本
 * @param {String} keyStr 解密key
 */
function decrypt(content, keyStr = 'etoF55gaHfgrER6e'){
	var key = CryptoJS.enc.Utf8.parse(keyStr);
	var decrypt = CryptoJS.AES.decrypt(content, key, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}

export {
	encrypt,
	decrypt
}